package com.siwei.mes.sync.tc.service;

import com.alibaba.fastjson.JSON;
import com.siwei.mes.entity.sync.tc.Waybill;
import com.siwei.mes.enums.MaterialsEnum;
import com.siwei.mes.enums.TcContrastExperimentTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 砼材运单
 *
 * @Description: 砼材运单
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2024/1/13 11:23
 */
@Service
public class SyncTcWaybillService {
    private static final Logger log = LoggerFactory.getLogger("tc");
    @Resource
    private GenMaterialQuickExperimentService genMaterialQuickExperiment;
    @Resource
    private GenMaterialBatchExperimentService genMaterialBatchExperiment;

    public void operateTcWaybill(Waybill entity) {
        log.info("正在处理砼材新增或修改运单,入参：{}", JSON.toJSONString(entity));
        /**根据砼材的类型 对照出 MES这边的类型*/
        TcContrastExperimentTypeEnum typeEnum = TcContrastExperimentTypeEnum.selectByTcType(entity.getProjectCategory());
        if (typeEnum == null) {
            log.info("对照出类型为空，不生成委托，砼材对应类型：【{}】", entity.getProjectCategory());
            return;
        }
        if (entity.getProjectName().contains("膨胀剂")) {
            log.info("物料名称为膨胀剂，不生成委托，砼材对应类型：【{}】，砼材对应物料名称：【{}】", entity.getProjectCategory(), entity.getProjectName());
            return;
        }

        if (typeEnum.getMesType().equals(MaterialsEnum.CONCRETE.getCode())) {
            log.info("原材料类型查询出混凝土，不做处理！");
            return;
        }


        /**原材料快检试验委托生成*/
        genMaterialQuickExperiment.genExperiment(typeEnum, entity);
        /**原材料批检试验委托生成*/
        genMaterialBatchExperiment.genExperiment(typeEnum, entity);
    }
}
